/*
 * @Author: wurangkun
 * @Date: 2024-05-14 09:00:32
 * @LastEditTime: 2024-05-22 17:50:46
 * @LastEditors: wurangkun
 * @FilePath: \flutter_example\lib\main.dart
 * @Description: 
 */
import 'package:flutter/material.dart';
import 'package:flutter_example/common/LocalModel.dart';
import 'package:flutter_example/common/ThemeModel.dart';
import 'package:flutter_example/common/UserModel.dart';
import 'package:flutter_example/common/global.dart';
import 'package:flutter_example/home/home.dart';
import 'package:flutter_example/routes/routes.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';

// void main() {
//   // ② 想使用Riverpod 的 Provider 必须用 ProviderScope 包裹MyApp！
//   runApp(const MyApp());

// }
void main() => Global.init().then((e) => runApp(const MyApp()));

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    // ScreenUtil.init(
    //     BoxConstraints(
    //       maxHeight: MediaQuery.of(context).size.height,
    //       maxWidth: MediaQuery.of(context).size.width,
    //     ) as BuildContext,
    //     designSize: const Size(750, 1624));

    return ScreenUtilInit(
        designSize: const Size(750, 1624),
        builder: (context, child) {
          return MultiProvider(
            providers: [
              ChangeNotifierProvider(create: (_) => ThemeModel()),
              ChangeNotifierProvider(create: (_) => LocalModel()),
              ChangeNotifierProvider(create: (_) => UserModel())
            ],
            child: Consumer2<ThemeModel, LocalModel>(
              builder: (BuildContext context, ThemeModel themeModel,
                  localeModel, child) {
                return MaterialApp(
                  debugShowCheckedModeBanner: false,
                  theme: ThemeData(
                    primarySwatch: themeModel.theme,
                  ),
                  // home: const HomePage(),
                  initialRoute: "/",
                  onGenerateRoute: onGenerateRoute,
                );
              },
            ),
          );
        });
  }
}
